<link rel="stylesheet" href="/static/css/bootstrap/bootstrap.min.css" />
<div class="content" style="width:95%;">
    <h3>管理员用户列表</h3>
    <hr />
    <div class="row ">
        <div class="col-md-10">
            <a class="btn btn-default save" href="{:url('manager/node/save')}">保存</a>
            <a class="btn btn-default generate" href="{:url('manager/node/generate')}">生成节点</a>
        </div>
    </div>
    <div class=".col-md-9" style="margin-top:20px;">
        <table class="table table-bordered">
            <tr class="active">
                <td>节点代码</td>
                <td>节点名</td>
                <td>操作</td>
            </tr>
            {volist name="rs" id="r"}
            <tr {if condition="$key%2"}class="active"{/if}>
            <td>{$r.code}</td>
            <td><input data-code="{$r.code}" value="{$r.name}" /></td>
            <td><a href="{:url('manager/node/delete')}?code={$r.code}" data-delete>删除</a></td>
            </tr>
            {/volist}
        </table>
    </div>
</div>

<script type="text/javascript">
$(function(){
    $('.btn.save').on('click', function(){
        var elem_inputs = $('[data-code]'),
                map = {};
        elem_inputs.each(function(i, e){
            var elem = $(e),
                    code = elem.attr('data-code'),
                    name = elem.val();
            if (name) map[code] = name;
        });
        $.ajax({
            url : '{:url("manager/node/save")}',
            data : {data : map},
            type : 'put',
            dataType : 'json',
            success : function(data) {
                alert(data.msg);
            }
        });
        return false;
    });

    $('.btn.generate').on('click', function(){
        $.ajax({
            url : '{:url("manager/node/generate")}',
            type : 'post',
            dataType : 'json',
            success : function(data) {
                alert(data.msg);
            }
        });
        return false;
    });

    $('[data-delete]').on('click', function(){
        var elem = $(this);
        $.ajax({
            url : elem.attr('href'),
            type : 'delete',
            dataType : 'json',
            success : function(data) {
                alert(data.msg);
            }
        });
        return false;
    });
});
</script>